/*
 * Copyright (C) 2011-2015 ShenZhen iBOXPAY Information Technology Co.,Ltd.
 * 
 * All right reserved.
 * 
 * This software is the confidential and proprietary
 * information of iBoxPay Company of China. 
 * ("Confidential Information"). You shall not disclose
 * such Confidential Information and shall use it only
 * in accordance with the terms of the contract agreement 
 * you entered into with iBoxpay inc.
 *
 */

package com.iboxpay.sdk;

import java.util.Collections;
import java.util.Map;

import org.apache.commons.beanutils.PropertyUtils;

/**
 * The class BeanUtil.
 *
 * Description: 
 *
 * @author: nieminjie
 * @since: 2016年2月29日	
 * @version: $Revision$ $Date$ $LastChangedBy$
 *
 */

public class BeanUtil {

	/**
	 * 对象转换成Map
	 * 
	 * @param obj
	 * @return
	 */
	public static Map<String, Object> toMap(Object obj) {
		Map<String, Object> map = Collections.emptyMap();
		if (null == obj) {
			return map;
		}

		if (obj instanceof Map) {
			return (Map) obj;
		}

		try {
			map = PropertyUtils.describe(obj);
		} catch (Exception e) {
			e.printStackTrace();
		}

		if (null != map && map.containsKey("class")) {
			map.remove("class");
		}
		return map;
	}
}
